local yanji = fk.CreateSkill{
    name = "wk_heg__yanji",
}

Fk:loadTranslationTable{
  ["wk_heg__yanji"] = "严纪",
  [":wk_heg__yanji"] = "其他角色的出牌阶段开始时，你可以展示所有手牌并选择将其中所有红色/黑色牌当【桃】/【杀】对其使用，然后你<a href=':DoGiveDeputy'>遣调</a>此武将牌于其至你回合开始。",

  ["wk_heg__yanji_black"] = "将黑色牌当【杀】使用",
  ["wk_heg__yanji_red"] = "将红色牌当【桃】使用",

  ["$wk_heg__yanji1"] = "权其轻重，而后施令。",
  ["$wk_heg__yanji2"] = "罪而后赦，以立恩威。",
}

local H = require "packages.ol_hegemony.util"
local HG = require "packages.new_heg_diy_my.util"

yanji:addEffect(fk.EventPhaseStart,{
    anim_type = "special",
    can_trigger = function(self, event, target, player, data)
      return player:hasSkill(yanji.name) and target ~= player and target.phase == Player.Play and not player:isKongcheng()
    end,
    on_use = function(self, event, target, player, data)
      local room = player.room
      local cards = player:getCardIds(Player.Hand)
      player:showCards(cards)
      local all_choices = {"wk_heg__yanji_black", "wk_heg__yanji_red"}
      local black = {}
      local red = {}
      for _, cid in ipairs(cards) do
        local card = Fk:getCardById(cid)
        if card.color == Card.Black then
          table.insertIfNeed(black, cid)
        end
        if card.color == Card.Red then
          table.insertIfNeed(red, cid)
        end
      end
      local choices = {}
      if #black > 0 and not player:prohibitUse(Fk:cloneCard("slash")) then
        table.insert(choices, "wk_heg__yanji_black")
      end
      if #red > 0 and not player:prohibitUse(Fk:cloneCard("peach")) and target.hp < target.maxHp then
        table.insert(choices, "wk_heg__yanji_red")
      end
      if #choices == 0 then return false end
      local choice = room:askToChoice(player, {
        choices = choices,
        skill_name = yanji.name,
        all_choices = all_choices})
      if choice == "wk_heg__yanji_black" then
        room:useVirtualCard("slash", black, player, target, yanji.name, true)
      else
        room:useVirtualCard("peach", red, player, target, yanji.name, true)
      end
      if (player.general == "wk_heg__zhaoyan" or player.deputyGeneral == "wk_heg__zhaoyan") and target:getMark("@wk_give_deputy") == 0 then
        if player.dead or target.dead then return end
        local isDeputy = H.inGeneralSkills(player, yanji.name)
        if isDeputy then
        HG.DoGiveDeputy(room, player, target, "wk_heg__zhaoyan", player.kingdom, isDeputy == "d")
        end
        room:setPlayerMark(player, "wk_give_deputy_zhaoyan", 1)
      end
    end,
})

yanji:addEffect(fk.TurnStart,{
    is_delay_effect = true,
    anim_type = "special",
    can_trigger = function(self, event, target, player, data)
      return target:getMark("wk_give_deputy_zhaoyan") == 1 and player:getMark("@wk_give_deputy") == "wk_heg__zhaoyan"
    end,
    on_cost = Util.TrueFunc,
    on_use = function(self, event, target, player, data)
      HG.StopGiveDeputy(player.room, player, yanji.name)
      player.room:setPlayerMark(target, "wk_give_deputy_zhaoyan", 0)
    end,
})

return yanji